﻿namespace Sitecore.ChangesTracker.Archiving
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Sitecore.Diagnostics;
  using Sitecore.Data;

  public class ArchiveDisabler:IDisposable
  {
    private static List<Guid> Ids=new List<Guid>();
    private static bool activeglobal;
    private Guid id = Guid.Empty;
    

    public ArchiveDisabler(Guid itemId)
    {
      Assert.ArgumentNotNull(itemId, "itemId");
      this.id = itemId;
      ArchiveDisabler.Ids.Add(itemId);
    }
    public ArchiveDisabler()
    {
      activeglobal = true;
    }
    public static void ActivateForItem(Guid itemId)
    {
      Ids.Add(itemId);
    }
    public static void DeactivateForItem(Guid itemId)
    {
      Ids.Remove(itemId);
    }
    public static bool IsActiveForItem(Guid itemId)
    {
      return Ids.Contains(itemId)||activeglobal;
    }
    
     

    public static bool IsActiveGlobal
    {
      get
      {
        return activeglobal;
      }
    }

    public void Dispose()
    {
      if(this.id==Guid.Empty)
      {
        activeglobal = false;
      }
      else
      {
        Ids.Remove(this.id);
      }
    }
   
  }
}
